package com.example.demo.bean;

import lombok.Data;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * 分页参数
 */
@Data
public class PageParam {
    private static final Long PAGE_NO = 1L;
    private static final Long PAGE_SIZE = 10L;

    private Long pageNo = PAGE_NO;
    private Long pageSize = PAGE_SIZE;
    private String sort;
    private List<SortParam> sortMap;

    public void setSort(String sort) {
        this.sort = sort;
        System.out.println("sort:"+sort);
        this.sortMap = new ArrayList<>();
        if (sort != null && !sort.isEmpty()) {
            String[] pairs = sort.split(";");
            for (String pair : pairs) {
                String[] entry = pair.split(",");
                if (entry.length == 2) {
                    SortParam sortParam = new SortParam();
                    sortParam.setSortField(entry[0]);
                    sortParam.setSortType(entry[1]);
                    this.sortMap.add(sortParam);
                }
            }
        }
    }
}
